package com.zh.controller;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;
import java.util.UUID;

@Controller
public class FileController {
    @RequestMapping(value = "/file1")
    public String fileUpLoad(MultipartFile file, HttpServletRequest req) throws IOException {
            String realPath = req.getServletContext().getRealPath("/img");
            UUID uuid = UUID.randomUUID();
            String s = uuid.toString();
            String name = file.getContentType();
            String[] split = name.split("/");
            System.out.println(realPath);
            System.out.println(s +"."+split[1]);
            file.transferTo(new File(realPath,s +"."+split[1]));
            return "SpringMvcDemo.html";

    }
}
